#include "Scores.h"
#include <sstream>
#include <stdlib.h>

unsigned int Scores::score;
unsigned int Scores::topScore;
int Scores::heartsCollected;
int Scores::PopeyeLives;

Scores::~Scores(void) { }

void Scores::Initialize(void) {
	score = 0;
	topScore = 0;
	PopeyeLives = 2;
}

void Scores::increaseScore(int points) {
	score += points;
}

void Scores::resetScore(void) {
	score = 0;
}

unsigned int Scores::getScore(void) {
	return score;
}

unsigned int Scores::getTopScore(void) {
	return topScore;
}

void Scores::changeTopScore(void) {
	if(score > topScore) topScore = score;
}

void Scores::gotHeart(void) {
	if(heartsCollected < 24) {
		heartsCollected++;
	}
}

bool Scores::doneCollecting(void) {
	if(heartsCollected < 24) return false;
	return true;
}

void Scores::lostPopeyeLife(void) {
	if(PopeyeLives > 0)
		PopeyeLives--;
}

const char* Scores::ScoreToString(void) {
	std::string s, top;
	std::stringstream strScore;
	std::stringstream strTopScore;
	std::stringstream final;

	char *buff;

	strScore << "000000" << score;
	strTopScore << "000000" << topScore;

	s = strScore.str();
	if(s.length() > 6) s = s.substr(s.length()-6, 6);
	else s = s.substr(6-s.length(), 6);
	
	top = strTopScore.str();
	if(top.length() > 6) top = top.substr(top.length()-6, 6);
	else top = top.substr(6-top.length(), 6);
	
	final << "I-" << s << " TOP-" << top;
	buff = strdup(final.str().c_str());
	return buff;
}